package xin.printk.android.utils;

import android.content.Context;
import android.content.SharedPreferences;

import xin.printk.android.BasicApplication;

public class PrefUtils {

    private static final String SP_NAME = "user_pref";

    public static void putString(String key, String value) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public static void putBoolean(String key, Boolean value) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public static void putInt(String key, int value) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt(key, value);
        editor.apply();
    }

    public static void putFloat(String key, float value) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putFloat(key, value);
        editor.apply();
    }

    public static void putFloat(String key, long value) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(key, value);
        editor.apply();
    }

    public static String getString(String key, String defaultValue) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return preferences.getString(key, defaultValue);
    }

    public static boolean getBoolean(String key, boolean defaultValue) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(key, defaultValue);
    }

    public static int getInt(String key, int defaultValue) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return preferences.getInt(key, defaultValue);
    }

    public static float getFloat(String key, float defaultValue) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return preferences.getFloat(key, defaultValue);
    }

    public static long getLong(String key, long defaultValue) {
        SharedPreferences preferences = BasicApplication.getContext()
                .getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return preferences.getLong(key, defaultValue);
    }
}
